package com.masterclient.app.modules.goods.newpage.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.eoner.baselibrary.bean.goods.BrandMessage;
import com.eoner.baselibrary.bean.goods.CommodityDetailData;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.base.MainViewHolder;
import com.masterclient.app.utils.CommonUtil;

public class NewCommodityDetailSellerAdapter extends DelegateAdapter.Adapter<MainViewHolder> {

    Activity mContext;

    private LayoutHelper mLayoutHelper;
    private boolean isShowArrow = true;

    private VirtualLayoutManager.LayoutParams mLayoutParams;
    private int mCount = 0;

    CommodityDetailData data;


    public NewCommodityDetailSellerAdapter(Activity context, LayoutHelper layoutHelper, int count) {
        this(context, layoutHelper, count, null, null,true);
    }

    public NewCommodityDetailSellerAdapter(Activity context, LayoutHelper layoutHelper, int count,
                                        @NonNull VirtualLayoutManager.LayoutParams layoutParams, CommodityDetailData data,boolean isShowArrow) {
        this.mContext = context;
        this.mLayoutHelper = layoutHelper;
        this.mCount = count;
        this.mLayoutParams = layoutParams;
        this.data = data;
        this.isShowArrow = isShowArrow;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @Override
    protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {

    }

    @Override
    public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public void onBindViewHolder(MainViewHolder holder, int position) {
        if (mLayoutParams != null) {
            holder.itemView.setLayoutParams(
                    new VirtualLayoutManager.LayoutParams(mLayoutParams));
        }

        ImageView iv_shop_logo = holder.itemView.findViewById(R.id.iv_shop_logo);
        TextView tv_shop_name = holder.itemView.findViewById(R.id.tv_shop_name);
        View rl_shop = holder.itemView.findViewById(R.id.rl_shop);
        View ll_arrow = holder.itemView.findViewById(R.id.ll_arrow);

        BrandMessage sellerMessage = data.getBrand();
        tv_shop_name.setText(sellerMessage.getName());
        if (isShowArrow){
            ll_arrow.setVisibility(View.VISIBLE);
            rl_shop.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    CommonUtil.goAnyWhere(mContext,sellerMessage.getUrl(),"","","","","");
                }
            });
        }else {
            ll_arrow.setVisibility(View.GONE);
        }
        ViewTransformUtil.glideImageView(mContext, sellerMessage.getLogo(), iv_shop_logo, R.mipmap.defaults, ScreenUtils.dp2px(70), ScreenUtils.dp2px(70));
    }

    @Override
    public int getItemCount() {
        return mCount;
    }

    @Override
    public int getItemViewType(int position) {
        return 5;
    }

}
